import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { defaultConfig } from 'app/theme/datatables-config-default';
import 'datatables';
@Component({
    selector: 'notification',
    templateUrl: 'notification.component.html'
})
export class NotificationComponent implements OnInit {
    @ViewChild('dataTable') table: ElementRef;
    private notificationTableUrl: string = '/water/boards';
    private dataTable: any;
    constructor() { }

    ngOnInit() {}

    ngAfterViewInit() {
        this.dataTable = jQuery(this.table.nativeElement).DataTable(this.assembleConfig());
     }

     assembleConfig() {
         let customConfg: any = {
             'ajax': {
                 'url': this.notificationTableUrl
             },
             'columns': [
                 {
                     'data': 'title',
                     'render': function ( data, type, row ) {
                         let date = row.createtime.substring(0, row.createtime.lastIndexOf(' ') );
                         return '<a href="/#/info-platform/notification/' + row.ids + '"><span class="date-time">' + date
                         + '<span> ' + data + '</a>';
                     }
                 },
             ]
         };

        return Object.assign({}, defaultConfig, customConfg);
     }
}